<?php

	// +----------------------------------------------------------------------
	// | 附件主页
	// +----------------------------------------------------------------------
	// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
	// +----------------------------------------------------------------------
	// | Author: 微尘 <yicmf@qq.com>
	// +----------------------------------------------------------------------

	namespace app\controller\file;

	use Qiniu\Auth as QuniuAuth;
	use Qiniu\Storage\UploadManager as QiniuUploadManager;
	use think\facade\Config;
	use Qiniu\Processing\PersistentFop;

	class Index extends Common
	{
		public function index()
		{

			$ffmpeg = \FFMpeg\FFMpeg::create(array(
				'ffmpeg.binaries' => '/usr/local/ffmpeg/bin/ffmpeg',
				'ffprobe.binaries' => '/usr/local/ffmpeg/bin/ffprobe',
				'timeout' => 30000, // The timeout for the underlying process
				'ffmpeg.threads' => 12, // The number of threads that FFMpeg should use
			));
			$video = $ffmpeg->open('/www/wwwroot/yiget/public/uploads/attachment/demo1.mp4');
			dump($video);

			exit();
			// 构建鉴权对象
			$auth = new QuniuAuth(Config::get('qiniu.access_key'), Config::get('qiniu.secret_key'));
			dump(Config::get('qiniu.access_key'));
			dump(Config::get('qiniu.secret_key'));
			dump(Config::get('qiniu.bucket'));
			// 生成上传 Token
			$token = $auth->uploadToken(Config::get('qiniu.bucket'));
			// 初始化 UploadManager 对象并进行文件的上传。
			$uploadMgr = new QiniuUploadManager();

			dump(Config::get('qiniu'));
			$key = 'video/oceans-clip.mp4';
			$config = new \Qiniu\Config();

			// 私有空间中的外链 http://<domain>/<file_key>
			$baseUrl = 'http://static2.file.yicmf.com/oceans-clip.mp4';
			// 对链接进行签名
			$signedUrl = $auth->privateDownloadUrl($baseUrl);

//         dump($signedUrl);
//         dump($config);
//         $bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
//         list($fileInfo, $err) = $bucketManager->stat(Config::get('qiniu.bucket'), $key);


			//要转码的文件所在的空间和文件名。
//         $key = 'qiniu.mp4';
			//转码是使用的队列名称。 https://portal.qiniu.com/mps/pipeline
			$pipeline = 'yicmf';
			$force = false;
			//转码完成后通知到你的业务服务器。
			$notifyUrl = 'notify.php';
			$config = new \Qiniu\Config();
			//$config->useHTTPS=true;
			$pfop = new PersistentFop($auth, $config);
			//要进行转码的转码操作。 http://developer.qiniu.com/docs/v6/api/reference/fop/av/avthumb.html
			$fops = "avthumb/m3u8/noDomain/1/vb/500k";
			list($id, $err) = $pfop->execute(Config::get('qiniu.bucket'), $key, $fops, $pipeline, $notifyUrl, $force);
			echo "\n====> pfop avthumb result: \n";
			if ($err != null) {
				dump($err);
			} else {
				dump($id);
			}

			//查询转码的进度和状态
			list($ret, $err) = $pfop->status($id);

			if ($err) {
				dump($err);
			} else {
				dump($ret);
			}

		}
	}
